@@ -236,3 +236,46 @@ def test_revision_based_on_deletion(self):
236
236
rev3 = Revision .objects .filter (id = rev3_id ).first ()
237
237
self .assertIsNotNone (rev3 , "The approved revision should not be deleted" )
238
238
self .assertEqual (rev3 .based_on , rev2 )
239
+
240
+ def test_revision_based_on_deletion_with_translation (self ):
241
+ """
242
+ Test the handling of a revision's "based_on" field, when it references a revision
243
+ created by a user that is deleted, within the context of a translation.
244
+ """
245
+ doc = DocumentFactory ()
246
+ rev1 = RevisionFactory (document = doc , creator = self .user )
247
+ rev2 = ApprovedRevisionFactory (document = doc , based_on = rev1 )
248
+
249
+ de_doc = DocumentFactory (parent = doc , locale = "de" )
250
+ de_rev = RevisionFactory (document = de_doc , based_on = rev1 )
251
+
252
+ it_doc = DocumentFactory (parent = doc , locale = "it" )
253
+ it_rev1 = RevisionFactory (document = it_doc , based_on = rev1 )
254
+ it_rev2 = RevisionFactory (document = it_doc , based_on = rev2 )
255
+
256
+ doc_id = doc .id
257
+ rev1_id = rev1 .id
258
+ rev2_id = rev2 .id
259
+ de_doc_id = de_doc .id
260
+ de_rev_id = de_rev .id
261
+ it_doc_id = it_doc .id
262
+ it_rev1_id = it_rev1 .id
263
+ it_rev2_id = it_rev2 .id
264
+
265
+ self .listener .on_user_deletion (self .user )
266
+
267
+ # Ensure that the based-on handling of revisions within parent-less
268
+ # documents is correct.
269
+ self .assertTrue (Document .objects .filter (id = doc_id ).exists ())
270
+ self .assertFalse (Revision .objects .filter (id = rev1_id ).exists ())
271
+ self .assertTrue (Revision .objects .filter (id = rev2_id , based_on = None ).exists ())
272
+
273
+ # Ensure that the un-approved translated revision is cascade deleted,
274
+ # and also that its document, if it no longer has any revisions, is
275
+ # also deleted.
276
+ self .assertFalse (Revision .objects .filter (id = de_rev_id ).exists ())
277
+ self .assertFalse (Document .objects .filter (id = de_doc_id ).exists ())
278
+
279
+ self .assertFalse (Revision .objects .filter (id = it_rev1_id ).exists ())
280
+ self .assertTrue (Revision .objects .filter (id = it_rev2_id , based_on = rev2 ).exists ())
281
+ self .assertTrue (Document .objects .filter (id = it_doc_id ).exists ())
0 commit comments